package com.base.vistter.iframe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.vistter.iframe.entity.InverterDevicesPowerSummary;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface InverterDevicesPowerSummaryMapper extends BaseMapper<InverterDevicesPowerSummary> {

    @Select("SELECT YEAR(report_time) AS report_time, ${column} FROM inverter_devices_power_year WHERE inverter_devices_id = #{devicesId} and is_delete = 0 GROUP BY YEAR(report_time) order by report_time ASC")
    List<InverterDevicesPowerSummary> statisticsDevicesSummary(@Param("column") String column, @Param("devicesId") Integer devicesId);

    @Select({"<script>",
    "SELECT SUM(dp) as dp , YEAR(report_time) as report_time from inverter_devices_power_summary where is_delete = 0 ",
    " <if test='stationId != null'> AND inverter_station_id = #{stationId} </if>",
    " GROUP BY YEAR(report_time) ORDER BY report_time ASC",
    "</script>"})
    List<InverterDevicesPowerSummary> statisticsSummary(@Param("stationId") Integer stationId);

}
